// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class OBSERVATION_REQUEST_OML_O33 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("32 OBR",32)]
  	    [HL7Field(HL7Version.v25, 32, HL7Repeat.False, HL7Required.True,"OBR")]
	    public OBR OBR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("33 TCD",33)]
  	    [HL7Field(HL7Version.v25, 33, HL7Repeat.False, HL7Required.False,"TCD")]
	    public TCD TCD {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("34 NTE",34)]
  	    [HL7Field(HL7Version.v25, 34, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("35 DG1",35)]
  	    [HL7Field(HL7Version.v25, 35, HL7Repeat.True, HL7Required.False,"DG1")]
	    public DG1[] DG1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("36 OBSERVATION",36)]
  	    [HL7Field(HL7Version.v25, 36, HL7Repeat.True, HL7Required.False,"OBSERVATION_OML_O33")]
	    public OBSERVATION_OML_O33[] OBSERVATION {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("41 PRIOR_RESULT",41)]
  	    [HL7Field(HL7Version.v25, 41, HL7Repeat.True, HL7Required.False,"PRIOR_RESULT_OML_O33")]
	    public PRIOR_RESULT_OML_O33[] PRIOR_RESULT {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			OBR = PopSegmentParseAndCheckRequired<OBR>(availableData, options, "OBR");
			TCD = PopSegmentParseAndCheckRequired<TCD>(availableData, options, "TCD");
			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
			DG1 = PopSegmentParseAndCheckRequiredArray<DG1>(availableData, options, "DG1");
			OBSERVATION = ProcessGroupArray<OBSERVATION_OML_O33>(availableData, options, "OBSERVATION");
			PRIOR_RESULT = ProcessGroupArray<PRIOR_RESULT_OML_O33>(availableData, options, "PRIOR_RESULT");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isOBR = availableData.StartsWith("OBR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OBR", options.Version) || isOBR) {
				return isOBR;
			}
			bool isTCD = availableData.StartsWith("TCD", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("TCD", options.Version) || isTCD) {
				return isTCD;
			}
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			bool isDG1 = availableData.StartsWith("DG1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("DG1", options.Version) || isDG1) {
				return isDG1;
			}
			OBSERVATION_OML_O33 testOBSERVATION_OML_O33 = new OBSERVATION_OML_O33();
			bool grpCCOBSERVATION_OML_O33 = (testOBSERVATION_OML_O33.CanConsume(availableData, options));
			if (IsRequired("OBSERVATION", options.Version) || grpCCOBSERVATION_OML_O33) {
				return grpCCOBSERVATION_OML_O33;
			}
			PRIOR_RESULT_OML_O33 testPRIOR_RESULT_OML_O33 = new PRIOR_RESULT_OML_O33();
			bool grpCCPRIOR_RESULT_OML_O33 = (testPRIOR_RESULT_OML_O33.CanConsume(availableData, options));
			if (IsRequired("PRIOR_RESULT", options.Version) || grpCCPRIOR_RESULT_OML_O33) {
				return grpCCPRIOR_RESULT_OML_O33;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "OBSERVATION_REQUEST";
			}
        }

        static OBSERVATION_REQUEST_OML_O33() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(OBSERVATION_REQUEST_OML_O33));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (OBR != null) {
			string segmentValue = OBR.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (TCD != null) {
			string segmentValue = TCD.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (DG1 != null && DG1.Length > 0) {
			for (int i = 0; i < DG1.Length; i++) {
				string segmentValue = DG1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (OBSERVATION != null && OBSERVATION.Length > 0) {
			for (int i = 0; i < OBSERVATION.Length; i++) {
				string segmentValue = OBSERVATION[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PRIOR_RESULT != null && PRIOR_RESULT.Length > 0) {
			for (int i = 0; i < PRIOR_RESULT.Length; i++) {
				string segmentValue = PRIOR_RESULT[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

